import { DtoValidation } from "src/Core/dto.validatorpip";
import { PaginateOptions, TrashedOptions } from '../config/types';
import { IsBoolean, IsDefined, IsEnum, IsNumber, IsOptional, IsUUID, Min } from "class-validator";
import { Transform } from "class-transformer";
import { toNumber } from 'lodash';
import { SelectTrashMode } from "src/config/defaultconfig";
import { toBoolean } from "src/Core";

@DtoValidation({type:'query'})
export class ListQueryDto implements  PaginateOptions{
    @Transform(({ value }) => toNumber(value))
    @Min(1, { message: '当前页必须大于1' })
    @IsNumber()
    @IsOptional()
    page = 1;

    @Transform(({ value }) => toNumber(value))
    @Min(1, { message: '每页显示数据必须大于1' })
    @IsNumber()
    @IsOptional()
    limit = 10;
}
@DtoValidation()
export class DeleteDto {
    @IsUUID(undefined, {
        each: true,
        message: 'ID格式错误',
    })
    @IsDefined({
        each: true,
        message: 'ID必须指定',
    })
    ids: string[] = [];
}@DtoValidation({ type: 'query' })
export class ListWithTrashedQueryDto extends ListQueryDto implements TrashedOptions {
    @IsEnum(SelectTrashMode)
    @IsOptional()
    trashed?: SelectTrashMode;
}
@DtoValidation()
export class DeleteWithTrashDto extends DeleteDto {
    @Transform(({ value }) => toBoolean(value))
    @IsBoolean()
    @IsOptional()
    trash?: boolean;
}
@DtoValidation()
export class RestoreDto {
    @IsUUID(undefined, {
        each: true,
        message: 'ID格式错误',
    })
    @IsDefined({
        each: true,
        message: 'ID必须指定',
    })
    ids: string[] = [];
}
